package com.jf.test.mvvm.base

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModel

/**
 * @Class: BaseAcVM
 * @Description:
 * @author: github.com/jackyflame
 * @Date: 2021/3/9
 */
abstract class BaseAcVM<out A:BaseActivity<*,*>,P:BasePresenter> : ViewModel() {

    private var mActivity: BaseActivity<*, *>? = null
    var mPresenter:P? = null

    fun init(activity:BaseActivity<*,*>){
        this.mActivity = activity;
        initPresenter(activity)
    }

    abstract fun initPresenter(owner: LifecycleOwner): P?

    fun getActivity():A?{
        return mActivity?.let { mActivity as A }
    }

    override fun onCleared() {
        super.onCleared()
        mActivity = null;
    }
}